import './assets/main.css';
import './assets/fontawesome-free-6.6.0-web/css/all.css';

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

// 引入element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import App from './App.vue'
import router from './router'
import axios from 'axios'
// import OSS from "ali-oss/lib/browser.js";
axios.defaults.headers['Content-Type'] = 'application/json';

axios.interceptors.request.use(config => {
    // 为请求头添加token字段为服务端返回的token
    config.headers['token'] = localStorage.getItem('token')

    // return config是固定用法 必须有返回值
    return config
})
// 全局引入 buffer（解决 ali-oss 依赖问题）
// window.Buffer = Buffer;
// window.process = process;



// axios.defaults.baseURL = 'http://fun.free.idcfengye.com'
axios.defaults.baseURL = 'http://62.234.92.252:20000'


axios.defaults.timeout = 10000
axios.interceptors.response.use(
    (response) => response,
    (error) => {
        if (error.response && error.response.status === 401) {
            localStorage.clear();
            router.push('/login');
        }
        return Promise.reject(error);
    }

);

const pinia = createPinia()



const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.use(router)
// 使用element-plus
app.use(ElementPlus)
app.use(pinia.use(piniaPluginPersistedstate))

app.mount('#app')
